<template>
	<view class="tabbar-container">
		<block>
			<view class="tabbar-item" v-for="(item,index) in tabbarList" :key="index"
				:class="[item.centerItem ? ' center-item' : '']" @click="changeItem(item)">
				<view :class="index === 2 ? 'item-top' : 'item-top'">
					<image :src="currentPage===item.id?item.selectIcon:item.icon"></image>
				</view>
				<view class="item-bottom" :class="[currentPage===item.id ? 'item-active' : '']">
					<text>{{item.text}}</text>
				</view>
			</view>
		</block>

	</view>
</template>

<script>
	export default {
		props: {
			currentPage: {
				type: Number,
				default: 0
			}
		},
		data() {
			return {
				currentItem: 0,
				tabbarList: [{
					id: 0,
					path: "/pages/index",
					icon: "/static/img/tabbar/home.png",
					selectIcon: "/static/img/tabbar/homeactive.png",
					text: "首页",
					centerItem: false
				}, {
					id: 1,
					path: "/pages/device/device",
					icon: "/static/img/tabbar/device.png",
					selectIcon: "/static/img/tabbar/deviceactive.png",
					text: "设备",
					centerItem: false
				}, {
					id: 2,
					path: "/pages/device/edit",
					icon: "/static/img/tabbar/add.png",
					selectIcon: "/static/img/tabbar/add.png",
					text: "",
					centerItem: true
				}, {
					id: 3,
					path: "/pages/device/alert",
					icon: "/static/img/tabbar/news.png",
					selectIcon: "/static/img/tabbar/newsactive.png",
					text: "报警",
					centerItem: false
				}, {
					id: 4,
					path: "/pages/mine/index",
					icon: "/static/img/tabbar/user.png",
					selectIcon: "/static/img/tabbar/useractive.png",
					text: "我的",
					centerItem: false
				}]

			};
		},
		mounted() {
			// this.currentItem = this.currentPage;
			// uni.hideTabBar();
		},
		methods: {
			changeItem(item) {
				let _this = this;
				// _this.currentItem = item.id;
				if (item.centerItem) {
					uni.navigateTo({
						url:item.path
					})
				} else {
					uni.switchTab({
						url: item.path
					});
				}
			}
		}
	}
</script>
<style>
	view {
		padding: 0;
		margin: 0;
		box-sizing: border-box;
	}

	.tabbar-container {
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;
		height: 130rpx;
		box-shadow: 0px 3px 20px rgba(0, 0, 0, 0.16);
		border-top: 1px;
		display: flex;
		align-items: center;
		padding: 5rpx 0;
		color: #999999;
		z-index: 200;
		background-color: #fff;
	}

	.tabbar-container .tabbar-item {
		width: 20%;
		height: 100rpx;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		text-align: center;
		margin-bottom: 10px;
	}

	.tabbar-container .item-active {
		color: #2F54EB;
		font-weight: bold;
	}

	.tabbar-container .center-item {
		display: block;
		position: relative;
	}

	.tabbar-container .tabbar-item .item-top {
		width: 54rpx;
		height: 54rpx;
		padding: 0rpx;
	}

	.tabbar-container .center-item .item-top {
		flex-shrink: 0;
		width: 100rpx;
		height: 100rpx;
		position: absolute;
		top: -50rpx;
		left: calc(50% - 50rpx);
		border-radius: 50%;
		box-shadow: 0 3px 20px rgba(0, 0, 0, 0.16);
		background: linear-gradient(0deg, #597EF7 100%, #2F54EB 0%);
		padding: 10rpx;

	}

	.tabbar-container .tabbar-item .item-top image {
		width: 100%;
		height: 100%;
	}

	.tabbar-container .center-item .item-top image {
		width: 50%;
		height: 50%;
    margin-top: 25%;
	}

	tabbar-container .tabbar-item:nth-child(3) .item-top image {
		background: #ff0000;
	}

	.tabbar-container .tabbar-item .item-bottom {
		font-size: 28rpx;
		width: 100%;
	}

	.tabbar-container .center-item .item-bottom {
		position: absolute;
		bottom: 5rpx;
	}
</style>